package com.pinc.poop;

import com.pinc.poop.R;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class image_button extends LinearLayout {
	private ImageView icon;
	private TextView  text;
	private Context context;

	public image_button(Context context, AttributeSet attrs) {
		super(context, attrs);

		this.context = context;
		LayoutInflater li = LayoutInflater.from(context);
		LinearLayout ll = (LinearLayout) li.inflate(R.layout.image_button, this);

		icon = (ImageView)ll.findViewById(R.id.imageView1);
		text = (TextView)ll.findViewById(R.id.textView1);
	}

	public image_button(Context context) {
		super(context);
		this.context = context;
		LayoutInflater li = LayoutInflater.from(context);
		LinearLayout ll = (LinearLayout) li.inflate(R.layout.image_button, this);

		icon = (ImageView)ll.findViewById(R.id.imageView1);
		text = (TextView)ll.findViewById(R.id.textView1);
	}

	public image_button setContent(int ImageId, String textstr)
	{
		icon.setImageDrawable(context.getResources().getDrawable(ImageId));
		text.setText(textstr);
		return this;
	}

	public Drawable getDrawable()
	{
		return icon.getDrawable();
	}

	public image_button setTextWidth(int w)
	{
		int width =  (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, w, getResources().getDisplayMetrics());
		text.setWidth(width);
		return this;
	}

	public image_button setTextSize(float dip)
	{
		text.setTextSize(dip);
		return this;
	}
}
